package com.cloudm.technician.ui.modules.cloudm_box.replace_success

import android.content.Intent
import android.os.Bundle
import android.view.View
import com.cloudm.technician.R
import com.cloudm.technician.data.model.DeviceInfo
import com.cloudm.technician.extensions.openActivity
import com.cloudm.technician.ui.base.BaseFragment
import com.cloudm.technician.ui.base.BasePresenter
import com.cloudm.technician.ui.modules.common.home.HomeActivity
import com.cloudm.technician.ui.widget.OnceClickListener
import kotlinx.android.synthetic.main.fragment_replace_success.*

/**
 * 作者: wesley
 * 时间: 2017/12/25
 * 描述: ui
 */
class ReplaceSuccessFragment : BaseFragment<BasePresenter>() {

    private var info: DeviceInfo? = null

    override val resource: Int
        get() = R.layout.fragment_replace_success

    companion object {
        fun newInstance(info: DeviceInfo?) = ReplaceSuccessFragment().apply {
            arguments = Bundle().apply {
                putParcelable("info", info)
            }
        }
    }

    override fun initInject() {

    }

    override fun handleBundle(bundle: Bundle) {
        info = bundle.getParcelable("info")
    }

    override fun initVariables() {

    }

    override fun initViews(view: View) {
        tvReplaceMsg.text = mContext.resources.getString(R.string.replace_success_msg,
                info?.deviceName ?: "")
    }

    override fun initListener() {
        tvReplaceSuccess.setOnClickListener(object : OnceClickListener() {
            override fun onOnceClick(view: View) {
                backHome()
            }
        })
    }

    fun backHome() {
        val intent = Intent(mContext, HomeActivity::class.java).apply {
            addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
            putExtras(Bundle().apply {
                putInt("flag", 1)
            })
        }
        mContext.openActivity(intent)
    }
}